package com.hmall.item.controller;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

/**
 * @Author: suren@517na.com
 * @CreateTime: 2025-04-25
 * @Description: a
 */
public class Test {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        String steps = null;
        int count = 0;
        while (in.hasNextLine()) { // 注意 while 处理多个 case
            if (in.hasNext()) {
                steps = in.next();
            }
            if (in.hasNextInt()) {
                count = in.nextInt();
            }
            if (steps == null || steps.length() == 0) {
                break;
            }
            steps = steps.substring(1, steps.length() - 1);
            String[] split = steps.split(",");
            int[] arr = new int[split.length];
            for (int i = 0; i < split.length; i++) {
                if (split[i].length() == 0) {
                    continue;
                }
                arr[i] = Integer.parseInt(split[i]);
            }

            int[] result = new int[2];
            test(arr, count, result);
        }


    }

    public static void test(int[] arr, int count, int[] result) {
        if (arr.length == 0) {
            return;
        }
        int minIndexSum = 0;
        for (int i = 0; i < arr.length; i++) {
            for (int j = i + 1; j < arr.length; j++) {
                if ((arr[i] + arr[j]) == count) {
                    if (minIndexSum == 0)  {
                        minIndexSum = i + j;
                        continue;
                    }
                    if (minIndexSum > i + j){
                        minIndexSum = i + j;
                    } else {
                        result[0] = arr[i];
                        result[1] = arr[j];
                    }
                }
            }
        }
        System.out.println(Arrays.toString(result));
    }
}
